﻿
using NineSeas.Models;
using System;
using System.ComponentModel.DataAnnotations;
using Orchard.ContentManagement;
using Orchard.Security;
namespace NineSeas.ViewModels
{
    public class AuthorProfileViewModel
    {
        public AuthorProfileViewModel()
        {
        }

        [StringLength(255), Display(Name = "DisplayName")]
        public string DisplayName { get; set; }

        [StringLength(255), Display(Name = "StatusMessage")]
        public string StatusMessage { get; set; }

        [StringLength(255), DataType(DataType.EmailAddress), Display(Name = "Email")]
        public string Email { get; set; }

        [StringLength(255), Display(Name = "Phone")]
        public string Phone { get; set; }

        public string BannerColor { get; set; }
        public string BackgroundColor { get; set; }
        public string ForeColor { get; set; }
        public string DateOfBirth { get; set; }

        public string AvatarUrl { get; set; }
        public string AvatarStoragePath { get; set; }

        public int TotalLikes { get; set; }
        public int WeekLikes { get; set; }
        public int BookCount { get; set; }

        public static AuthorProfileViewModel FromPart(AuthorProfilePart part)
        {
            if (part == null) return null;
            var viewModel = new AuthorProfileViewModel();
            viewModel.DisplayName = part.DisplayName;
            viewModel.StatusMessage = part.StatusMessage;
            viewModel.Phone = part.Phone;
            viewModel.BannerColor = part.BannerColor;
            viewModel.BackgroundColor = part.BackgroundColor;
            viewModel.ForeColor = part.ForeColor;
            viewModel.DateOfBirth = part.DateOfBirth;
            viewModel.AvatarUrl = part.AvatarUrl;
            viewModel.AvatarStoragePath = part.AvatarStoragePath;
            viewModel.TotalLikes = part.TotalLikes;
            viewModel.WeekLikes = part.WeekLikes;
            viewModel.BookCount = part.BookCount;

            var user = part.As<IUser>();
            if (user != null)
            {
                viewModel.Email = user.Email;
            }

            return viewModel;
        }
    }
}